﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Libs.HR;

public partial class Pages_Hr_FamilyType_Edit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        AppUtils.CheckLogin();
        Title = Title + " - Cập nhật quan hệ gia đình";
        if (IsPostBack) return;
        btDelete.Attributes.Add("onclick", "return confirm('Bạn có đồng ý xóa?');");
        init();
    }

    private void init()
    {
        var _FamilyType = new FamilyType() { TypeID = AppUtils.Request("id") };
        _FamilyType = _FamilyType.Get();
        if (_FamilyType == null) Response.Redirect(Constant.ADMIN_PATH + Resources.Url.FamilyTypeList);
        txtName.Text = _FamilyType.Name;
        txtOrder.Text = _FamilyType.Order.ToString();
        drpGender.SelectedValue = _FamilyType.Gender.ToString();
        txtDescription.Text = _FamilyType.Description;
    }

    protected void btUpdate_Click(object sender, EventArgs e)
    {
        var _FamilyType = new FamilyType() { TypeID = AppUtils.Request("id") };
        _FamilyType = _FamilyType.Get();
        _FamilyType.Name = txtName.Text.Trim();
        _FamilyType.Order = Convert.ToInt32(txtOrder.Text);
        _FamilyType.Gender = Convert.ToInt32(drpGender.SelectedValue);
        _FamilyType.Description = txtDescription.Text.Trim();
        _FamilyType.Update();

        Response.Redirect(Constant.ADMIN_PATH + Resources.Url.FamilyTypeList);
    }

    protected void btDelete_Click(object sender, EventArgs e)
    {
        FamilyType _FamilyType = new FamilyType() { TypeID = AppUtils.Request("id") };
        _FamilyType.Delete();
        Response.Redirect(Constant.ADMIN_PATH + Resources.Url.FamilyTypeList);
    }

    protected void btCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect(Constant.ADMIN_PATH + Resources.Url.FamilyTypeList);
    }

}
